<template>
  <view class="classify">
    <topbar title="分类" />
    <view class="searcher">
      <input
        type="text"
        placeholder="请输入商品名称"
        placeholder-style="font-size: 24rpx;color:#666666;"
      />
      <uni-icons type="search" size="20" color="#DEDDE0" class="search-icon" />
    </view>
    <!-- scroll-into-view拿到元素的id值 -->
    <scroll-view scroll-x :scroll-into-view="viewId" style="height: 184rpx;">
      <view class="container">
        <view
          class="electrical"
          v-for="(item, i) in 18"
          @click="handlePicrute(i)"
          :key="i"
          :id="`electrical-${i}`"
        >
          <image
            src="/src/images/bing.png"
            mode="scaleToFill"
            :class="{ active: index === i }"
          />
          <view class="name">家用电器</view>
        </view>
      </view>
    </scroll-view>
    <view class="seacond-classify">
    <view class="scroll">
      <view v-for="(item, i) in 5" @click="handleSlide(i)">
        <view class="slide-name" :class="{ active: index === i }"
          >家用电器</view
        >
      </view>
      </view>
      <scroll-view scroll-y scroll-left>
    <view class="list" v-for="item in 5">
<image class="img" src="/src/images/phone.png" mode="aspectFill" /> 
<view class="list-item">
<view class="title">苹果15 iPhone15 全新未激活全网通手机海外</view>
<view class="buy">
<view class="price">￥5189.00</view>
<view class="payFor">去购买</view>
</view>
</view>
    </view>  
      </scroll-view>
</view>
    
  </view>
</template>

<script setup>
import topbar from "@/component/topbar.vue";
import { UniIcons } from "@dcloudio/uni-ui/lib/uni-icons/uni-icons.vue";
import { ref } from "vue";
const index = ref(0);
const viewId =ref('')
// 当选中图片的时候，让选中的索引和我当前定义的索引一致
const handlePicrute = (i) => {
  index.value = i;

};
//滑动侧边实现联动滑动
const handleSlide = (i)=>{
    index.value = i;
    viewId.value = `electrical-${i}`;
}
</script>

<style lang="scss" scoped>
.classify {

  .searcher {
    position: relative;
      margin: 0 32rpx;
    input {
      width: 614rpx;
      height: 48rpx;
      background: #e3f0ff;
      border-radius: 40rpx;
      padding-left: 72rpx;
      margin-top: 24rpx;
    }
    .search-icon {
      position: absolute;
      top: 5rpx;
      left: 0;
      width: 25rpx;
      height: 25rpx;
      margin-left: 22rpx;
    }
  }
  .container {
      margin: 0 32rpx;
    margin-top: 34rpx;
    // display: flex;
    // align-items: center;
    display: inline-flex;
    align-items: flex-start;
    .electrical {
      white-space: nowrap;
      display: inline-block;

      image {
        width: 100rpx;
        height: 100rpx;
        background: #ffffff;
        border-radius: 56rpx 56rpx 56rpx 56rpx;
        margin-right: 42rpx;
        &.active {
          border: 2rpx solid #08f56b;
        }
      }
      .name {
        width: 96rpx;
        height: 32rpx;
        background: linear-gradient(90deg, #e44b18 0%, #f42e1f 100%);
        border-radius: 4rpx 4rpx 4rpx 4rpx;
        text-align: center;
        line-height: 32rpx;
        margin-right: 50rpx;
        font-size: 20rpx;
        color: #e3f0ff;
      }
    }
  }
  .seacond-classify{
    display: flex;
margin-top: 8rpx;
margin-right: 32rpx;
  .scroll {
    .slide-name {
      width: 160rpx;
      height: 96rpx;
      background: #f4f4f4;
      font-size: 28rpx;
      color: #666666;
      text-align: center;
      line-height: 96rpx;
      &.active {
        background: #ffffff;
        color: #f62a20;
      }
    }
  }
  .list{
margin-left: 16rpx;
margin-top: 8rpx;
display: flex;
margin-bottom: 16rpx;
 box-shadow: 0 10rpx 30rpx rgba(0, 0, 0, 0.15);
.img{
width: 180rpx;
height: 179rpx;
background: rgba(217,217,217,0);
}
.list-item{
margin-left: 16rpx;
.title{
width: 346rpx;
height: 80rpx;
font-family: 'Source Han Sans CN, Source Han Sans CN';
font-weight: 500;
font-size: 26rpx;
color: #333333;
line-height: 40rpx;
text-align: justified;
font-style: normal;
text-transform: none;
margin-top: 10rpx;
}
.buy{
    display: flex;
    margin-top: 48rpx;
    justify-content: space-between;
    align-items: center;
.price{
    font-size: 24rpx;
color: #F62A20;
}
.payFor{
width: 88rpx;
height: 32rpx;
border-radius: 16rpx 16rpx 16rpx 16rpx;
border: 2rpx solid #F62A20;
font-size: 20rpx;
color: #F62A20;
margin-left: 122rpx;
text-align: center;
line-height: 32rpx;
}
}
}
  }
}
}
</style>
